package ae.pcfc.cldos.online.web.controller.client.company.nocandletters;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;

import ae.pcfc.cldos.online.common.clddb.domain.ServiceMaster;
import ae.pcfc.cldos.online.common.delegate.FnpGSDelegate;
import ae.pcfc.cldos.online.common.vo.FnpParamsVO;
import ae.pcfc.cldos.online.fnp.service.client.vo.FNPCatalogVO;
import ae.pcfc.cldos.online.fnp.service.client.vo.FNPParameterVO;
import ae.pcfc.cldos.online.web.Constants;
import ae.pcfc.cldos.online.web.controller.base.BasePageController;
import ae.pcfc.cldos.online.web.services.fnp.FnpParametersCheckService;

public class NocAndLettersFnpCommonController extends BasePageController {
	
	@Autowired
	@Qualifier("FnpGSDelegate")
	@Resource(name = "FnpGSDelegate")
	private FnpGSDelegate fnpGSDelegate;
	
	@Autowired
	private FnpParametersCheckService fnpParametersCheckService;
	
	protected FnpGSDelegate getFnpGSDelegate() {
		return fnpGSDelegate;
	}
	
	protected FnpParametersCheckService getFnpParametersCheckService() {
		return fnpParametersCheckService;
	}
	
	protected void processFnp(HttpServletRequest request, String fnpServiceCode, BindingResult errors, FnpParamsVO fnpParamsVO) {
		List<FNPParameterVO> allParams = getFnpGSDelegate().retreiveFNPParameters(Arrays.asList(new String[]{fnpServiceCode}));
		List<FNPParameterVO> notFeeled = getFnpParametersCheckService().feelParamsAndGetNotFeeled(request, allParams);
		if(notFeeled.size()>0){
			errors.reject("sdgsd", "Recomplete payment info please");
		} else {
			fnpParamsVO.setFnpParams(allParams);			
		}
	}

	@ModelAttribute(Constants.__FNP_CATALOG_MODEL_KEY)
	public List<FNPCatalogVO> populateFinanceReviewerInfoModel(HttpServletRequest request) {
			return fnpGSDelegate.getFnpCatalogVOsByServiceCode(ServiceMaster.NOC_LETTER.toString());		
	}

}
